package com.javatom.notes.feign;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
//hystrix
@EnableCircuitBreaker
//断路器Dashboard监控仪表
@EnableHystrixDashboard
public class FeignOperatApplication {
//    断路器Dashboard监控仪表 http://localhost:8781/hystrix
//
//    Hystrix Dashboard输入： http://localhost:8781/actuator/hystrix.stream
    public static void main(String[] args) {
        SpringApplication.run(FeignOperatApplication.class, args);
    }
    @Bean
    public ServletRegistrationBean getServlet() {

        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();

        ServletRegistrationBean regBean = new ServletRegistrationBean(streamServlet);

        regBean.setLoadOnStartup(1);

        List mappingList = new ArrayList();

        mappingList.add("/hystrix.stream");

        regBean.setUrlMappings(mappingList);

        regBean.setName("HystrixMetricsStreamServlet");

        return regBean;

    }

}
